package com.chixing.ih.module.task.mapper.provider;

import com.chixing.ih.module.task.pojo.ChargeBack;
import com.chixing.ih.status.IsDeleteEnum;
import com.chixing.ih.util.EmptyUtil;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;

/**
 * 目的:
 *
 * @author ：zcw
 * @version: 1.0  2020/9/25 23:02
 */
public class ChargeBackMapperProvider {
    public String saveOne() {
        return new SQL() {{
            INSERT_INTO("tbl_chargeback");
            INTO_COLUMNS("order_id", "refund_amount", "reason_for_refund", "create_time");
            INTO_VALUES("#{orderId}", "#{refundAmount}", "#{reasonForRefund}", "#{createTime}");
        }}.toString();
    }

    public String deleteOne() {
        return new SQL() {{
            DELETE_FROM("tbl_chargeback");
            WHERE("id = #{chargeBackId}");
        }}.toString();
    }

    public String updateOne(ChargeBack chargeBack) {
        return new SQL() {{
            UPDATE("tbl_chargeback");
            if (!EmptyUtil.isEmpty(chargeBack.getOrderId())) {
                SET("order_id = #{orderId}");
            }
            if (!EmptyUtil.isEmpty(chargeBack.getRefundAmount())) {
                SET("refund_amount = #{refundAmount}");
            }
            if (!EmptyUtil.isEmpty(chargeBack.getReasonForRefund())) {
                SET("reason_for_refund = #{reasonForRefund}");
            }
            if (!EmptyUtil.isEmpty(chargeBack.getCreateTime())) {
                SET("create_time = #{createTime}");
            }
            if (!EmptyUtil.isEmpty(chargeBack.getUpdateTime())) {
                SET("update_time = #{updateTime}");
            }
            if (!EmptyUtil.isEmpty(chargeBack.getLogicalDeletion())) {
                SET("is_deleted = #{logicalDeletion}");
            }
            if (!EmptyUtil.isEmpty(chargeBack.getOutRequestNo())) {
                SET("out_request_no = #{outRequestNo}");
            }
            WHERE("order_id = #{chargeBackId}");
        }}.toString();
    }

    public String findOne() {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_chargeback");
            WHERE("id = #{chargeBackId}");
            AND().WHERE("is_deleted = " + IsDeleteEnum.ZERO.status);
        }}.toString();
    }

    public String findAll() {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_chargeback");
            WHERE("is_deleted = " + IsDeleteEnum.ZERO.status);
        }}.toString();
    }

}
